const POST = 8001;

var app = require('http').createServer();
var io = require('socket.io')(app);
var userCount = 0;

app.listen(POST);
console.log("WebSocket Server Linstening on POST:" + POST);

io.on('connection', function (socket) {

    userCount++;
    socket.nickname = "USER" + userCount;
    console.log("[ENTER]\t", socket.nickname);
    io.emit("enter", socket.nickname + '  ENTER');

    socket.on("message", function (str) {
        io.emit("message", socket.nickname + ' SAYS: ' + str);
        console.log("[MSG]\t", socket.nickname, " \t SAY: ", str);

    });

    socket.on("disconnect", function () {
        io.emit("disconnect", socket.nickname + ' LEFT')
        console.log("[LEFT]\t", socket.nickname);

    });
});
